<?php
/**
 * Description:用户相关
 * User: wh
 * Date: 2017-07-27
 * Time: 17:37
 */
namespace app\wxbackend\controller\Wx;

class WxUser 
{

    /**
     * @comment 微信端获取用户列表
     * @param $nextOpenId 下一个用户id
     * @author wuhao
     * @return array
     */
    public static function getList($nextOpenId = null)
    {
        //$nextOpenId = 'o2-PovhLDjsRJxhWKyXQHYyVn12c';
        $access_token = WxAccessToken::getAccessToken();
        if ($nextOpenId) {
            $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token.'&next_openid='.$nextOpenId;
        } else {
            $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token;
        }

        $res = Curl::callWebServer($url, '', 'GET');
        if ($res['count'] == 10000) {
            //dd($res, $res['next_openid']);
            $new  = self::getList($res['next_openid']);  //递归获取接下来的
            if ($new && $new['count'] > 0) {
                $res['data']['openid'] = array_merge_recursive($res['data']['openid'], $new['data']['openid']); //合并OpenID列表
            }
        }
        return $res;
    }

    /**
     * @comment 得到微信端用户信息
     * @author wuhao
     * @param $openId
     * @return bool
     */
    public static function getUserInfo($openId)
    {
        if (!$openId) {
            return false;
        }

        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$openId;
        $res = Curl::callWebServer($url, '', 'GET');
        var_dump($res);
    }
}